package com.zhongkun.datahome.service.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongkun.datahome.service.domain.Project;
import com.zhongkun.datahome.service.mapper.ProjectMapper;
import com.zhongkun.datahome.service.req.qry.project.ProjectQry;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.Objects;

/**
 * @Author: lifengsheng
 * @Date: 2025/4/14 17:15
 * @Desc
 */
@Repository
public class ProjectRepository extends ServiceImpl<ProjectMapper, Project> {
    public IPage<Project> page(ProjectQry qry) {
        IPage<Project> page = new Page<>(qry.getPageNo(), qry.getPageSize());
        return this.page(page, new LambdaQueryWrapper<Project>()
                .like(StringUtils.isNotBlank(qry.getProjectName()), Project::getProjectName, qry.getProjectName())
                .eq(Objects.nonNull(qry.getStatus()), Project::getStatus, qry.getStatus())
                .orderByDesc(Project::getId));
    }
}
